<?php

/*获取完整添加好友验证信息的action*/
/*
验证信息来源: 0=账号查找，1=条件查找，2=群聊天，3=临时会话，4=其他
*/
include '../include/init.php';
$uid=$_POST['u'];
$type=$_POST['t'];
$usr=new userModel();

if($type=="addfrd")
{
	$af=new addfrdModel();
	$frd=new frdModel();
	//获取所有[未处理]的好友验证信息(ignord_this=0)
	//$afmsg=$af->getdoing($uid);
	$afmsg=$af->getall($uid);

	if($afmsg)
	{
		$afm=array();
		foreach($afmsg as $k=>$v)
		{
			$fid=$uid==$v['ownid']?$v['toid']:$v['ownid'];
			if($v['isread']==0)
			{
				$af->hasread($v['id']);
			}
			//获取用户的头像，昵称，年龄，居住地，及是否开通空间
			$user=$usr->getsome($fid,array('id','name','imghead_60 as img','imghead_gray as imggray','sex','birthday','hometown','livetown'));
			if($user)
			{
				$user['uid']=$user['id'];
				unset($user['id']);
			}
			if($v['ignore_this']==1)
			{
				$v['class']='ignored';
			}
			else
			{
				/*
				//本用户与该用户关系
				$usrfrd=$frd->isfrd($uid,$v['ownid']);
				//该用户与本用户关系
				$frdusr=$frd->isfrd($v['ownid'],$uid);
				$relation=$usrfrd+$frdusr;
				if($relation==1)
				{
					$v['class']='oneadd';
				}
				else if($relation==2)
				{
					$v['class']='hasadd';
				}
				else
				{
					$v['class']='';
				}
				*/
				
				

				$relation=$frd->bothfrd($uid,$fid);
				if($relation==1&&$v['isadd']==1)
				{
					$v['class']='hasadd';
				}
				else if($relation==2&&$v['isadd']==1)
				{
					//$v['class']=$uid==$v['ownid']?'imadd':'oneadd';
					$v['class']='imadd';
				}
				else if($relation==3&&$v['isadd']==1)
				{
					//$v['class']=$uid==$v['ownid']?'oneadd':'imadd';
					$v['class']='oneadd';
				}
				else
				{
					$v['class']='';
				}
				/*
				if($v['isadd']==1)
				{
					$v['class']='hasadd';
				}
				*/
				if($v['isadd']==0)
				{
					$v['class']=$uid==$v['ownid']?'berefused':'refused';
				}
				
			}
			$afm[]=array_merge($v,$user);
		}

		if(!empty($afm))
		{
			echo json_encode($afm);
			exit;
		}
	}
	echo json_encode(false);
	exit;
}
else if($type="grpsys")
{

}